package com.tuanbiao.ui.log;

import android.content.Context;
import android.content.Intent;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.abiao.lib_utils.ViewUtils;
import com.hzjq.data.hzjq.entity.LogEntity;
import com.tuanbiao.R;
import com.tuanbiao.base.mvp.BasePresenterActivity;
import com.tuanbiao.controllers.LogController;
import com.tuanbiao.databinding.ActivityLogBinding;
import com.tuanbiao.models.LogModel;
import com.tuanbiao.presenter.LogOperatePresenter;
import com.tuanbiao.utils.LibCollections;

import java.util.List;

public class LogOperateActivity extends BasePresenterActivity<LogOperatePresenter, ActivityLogBinding> implements LogController.View {
    private LogOperateAdapter logOperateAdapter;

    public static void start(Context context) {
        Intent starter = new Intent(context, LogOperateActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected ActivityLogBinding getBindingView() {
        return ActivityLogBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView() {
        binding.ivToolbarBack.setOnClickListener(getBackListener());
        binding.rvContent.setLayoutManager(new LinearLayoutManager(getActivity()));
        logOperateAdapter = new LogOperateAdapter();
        binding.rvContent.setAdapter(logOperateAdapter);
    }


    @Override
    protected LogOperatePresenter createPresenter() {
        return new LogOperatePresenter(new LogModel(), this);
    }

    @Override
    public void setItems(List<LogEntity> logs) {
        if (LibCollections.isEmpty(logs)) {
            logOperateAdapter.setEmptyView(ViewUtils.layoutId2View(R.layout.include_no_data));
        }
        logOperateAdapter.setNewInstance(logs);
    }
}